<script setup>
import { ref } from "vue";
import { useI18n } from "vue-i18n";
import { useConfigStore } from "@/store/modules/config";

const useConfig = useConfigStore();

const { locale } = useI18n();
const isShow = ref(false);
let lang = localStorage.getItem("lang") || "ch";

// 切换英文
function changeLang() {
  const _lang = localStorage.getItem("lang");
  const newVal = _lang && _lang === "ch" ? "en" : "ch";
  lang = newVal;
  locale.value = newVal;
  localStorage.setItem("lang", newVal);
}

function showDialog() {
  if (useConfig.account) return;
  isShow.value = true;
}
function closeDialog() {
  isShow.value = false;
}
</script>

<template>
  <div class="div-wallet">
    <div class="wallet" @click.stop="showDialog">
      <img src="@/assets/icon-wallet.png" width="32" height="32" alt="" />
      {{ useConfig.getEncryptAccount ?? $t("home.linkWallte") }}
    </div>
    <div class="div-change" @click="changeLang">
      <img src="@/assets/icon-change.png" width="19" height="19" alt="" />
      {{ lang == "ch" ? $t("home.ch") : $t("home.en") }}
    </div>
  </div>

  <!--提示框-->
  <div v-show="isShow" class="div-dialog">
    <div class="div-dialog-bg" />
    <div class="dialog-content">
      <div class="text">{{ $t("home.confirmBindWallte") }}</div>
      <div class="div-footer">
        <div class="div-btn div-btn-cancel" @click.stop="closeDialog">
          {{ $t("home.cancel") }}
        </div>
        <div class="div-btn div-btn-sure" @click.stop="useConfig.I_ACCOUNT">
          {{ $t("home.confirm") }}
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.div-wallet {
  height: 44px;
  padding: 0 14px;
  display: flex;
  font-size: 14px;
  justify-content: space-between;
  & > div {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .wallet {
    padding-left: 10px;
    padding-right: 10px;
    border-radius: 20px;
    border: 1px solid #9cb3bf;
  }
}

.div-dialog {
  position: absolute;
  width: 260px;
  left: calc(50% - 130px);
  top: 30%;
  z-index: 22;
  &-bg {
    position: fixed;
    left: 0px;
    top: 0px;
    bottom: 0px;
    right: 0px;
    opacity: 0.7;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1;
  }
  .dialog-content {
    position: absolute;
    left: 0px;
    font-weight: 500;
    font-size: 14px;
    color: #ffffff;
    line-height: 20px;
    z-index: 1111;
    text-align: center;
    width: 100%;
    padding: 30px 10px 20px;
    border: 1px solid #24302d;
    opacity: 0.99;
    border-radius: 20px;
    background: linear-gradient(
      135deg,
      rgba(253, 253, 253, 0.22) 0%,
      rgba(253, 253, 253, 0.22) 0%,
      rgba(243, 243, 243, 0) 100%
    );
    .div-footer {
      margin-top: 20px;
      display: flex;
      justify-content: space-evenly;
      gap: 20px;
      .div-btn {
        height: 40px;
        background: #676b7c;
        border-radius: 8px;
        width: 120px;
        font-size: 13px;
        display: flex;
        align-items: center;
        justify-content: center;
        &-cancel {
          background-color: #676b7c;
        }
        &-sure {
          background: linear-gradient(57deg, #47ddc2 0%, #c1ffc8 100%);
        }
      }
    }
  }
}
</style>
